import { BaseWindow } from "../../../../component/window/BaseWindow";
import { PageTool } from "../../../../common/global/PageTool";
import { Language } from "../../../../../extend/language/Language";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GComboBox } from "../../../../../com/mui/controls/GComboBox";
import { MailFriendItemCellRender } from "../../mail/MailFriendItemCellRender";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { GTextInput } from "../../../../../com/mui/controls/GTextInput";
import { GameConst } from "../../../../component/gconst/GameConst";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { ManorListPanel } from "./ManorListPanel";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
//class GuildManorListWindow
    
    export  class GuildManorListWindow extends BaseWindow
    {
        constructor()
        {
            super();
            this._pageTool = new PageTool([], 9);
            this.setSize(577, 415);
            titleHeight = 35;
            title = Language.getString(57077);
            this.addEventListener(flash.events.Event.CHANGE, this.onCurPageChangeHandler);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this._campText = new GTextFiled();
            this._campText.textColor = 16580298;
            this._campText.text = Language.getString(57078);
            this._campText.x = 50;
            this._campText.y = 50;
            this.addChild(this._campText);
            this._campCombo = new GComboBox();
            this._campCombo.move(90, 50);
            this._campCombo.width = 100;
            this._campCombo.height = 20;
            this._campCombo.buttonMode = true;
            this._campCombo.styleName = "GComboboxStyle";
            this._campCombo.drawNow();
            this._campCombo.dropdown.setStyle("cellRenderer", MailFriendItemCellRender);
            this._campCombo.dropdown.setStyle("skin", ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB));
            this._campCombo.textField.setStyle("textFormat", new GTextFormat("", 12, 11661308, false, false, false, "", "", flash.text.TextFormatAlign.CENTER));
            var loc1=new DataProvider();
            loc1.addItem({"id": 0, "label": Language.getString(57079)});
            loc1.addItem({"id": 1, "label": Language.getString(57080)});
            loc1.addItem({"id": 2, "label": Language.getString(57081)});
            loc1.addItem({"id": 3, "label": Language.getString(57082)});
            this._campCombo.dataProvider = loc1;
            this._campCombo.selectedIndex = 0;
            this._campCombo.addEventListener(flash.events.Event.CHANGE, this.onCampComboBoxChangeHandler);
            addChild(this._campCombo);
            this._guildNameText = new GTextFiled();
            this._guildNameText.textColor = 16580298;
            this._guildNameText.text = Language.getString(57083);
            this._guildNameText.x = 225;
            this._guildNameText.y = 50;
            this.addChild(this._guildNameText);
            this._nameInput = new GTextInput();
            this._nameInput.maxChars = GameConst.GuildNameLimit;
            this._nameInput.styleName = "GTextInput";
            this._nameInput.name = "searchName";
            this._nameInput.width = 155;
            this._nameInput.x = 290;
            this._nameInput.y = 50;
            this.addChild(this._nameInput);
            this._searchButton = new GButton();
            this._searchButton.styleName = "Button";
            this._searchButton.label = Language.getString(57084);
            this._searchButton.setSize(68, 28);
            this._searchButton.move(460, 48);
            this._searchButton.addEventListener(flash.events.MouseEvent.CLICK, this.onSearchBtnClickHandler);
            this.addChild(this._searchButton);
            this._guildListPanel = new ManorListPanel();
            this._guildListPanel.x = 15;
            this._guildListPanel.y = 75;
            this.addChild(this._guildListPanel);
            this._tipText = ObjCreate.createTextField(Language.getString(57085), 370, 375, 220, 20, this, GlobalStyle.textFormat6);
            this._tipText.autoSize = flash.text.TextFieldAutoSize.LEFT;
            return;
        }

        /* internal  */onCampComboBoxChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            this.onSearchBtnClickHandler(null);
            return;
        }

        /* internal  */onSearchBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=this._campCombo.selectedItem.id;
            var loc2=this._nameInput.text;
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildGetSpaceList, {"camp": loc1, "guildName": loc2}));
            return;
        }

        public updateGuildDataProvider(arg1: Array<any>): void
        {
            this._pageTool.array = arg1;
            this._guildListPanel.updateDataProvider(this._pageTool.getByPageNo(1));
            this._guildListPanel.pageBar.maxPage = this._pageTool.pagesCount;
            return;
        }

        public onCurPageChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=this._guildListPanel.pageBar.currentPage;
            this._guildListPanel.updateDataProvider(this._pageTool.getByPageNo(loc1));
            return;
        }

        /* internal */ /* var */_campText: GTextFiled;

        /* internal */ /* var */_campCombo: GComboBox;

        /* internal */ /* var */_guildNameText: GTextFiled;

        /* internal */ /* var */_nameInput: GTextInput;

        /* internal */ /* var */_searchButton: GButton;

        /* internal */ /* var */_guildListPanel: ManorListPanel;

        /* internal */ /* var */_tipText: Object /* flash.text.TextField */;

        /* internal */ /* var */_pageTool: PageTool;
    }
